package com.kqzz.common.config.swagger;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import com.google.common.base.Predicates;

import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ClassName :Swagger2Config
 * @Description : swagger API文档 配置类   http://ip:host//doc.html
 * @Author :文金文
 * @Date :2020/11/27 10:42
 **/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class Swagger2Config {

    @Bean
    public Docket creatSysApi(){
        List<Parameter> pars = new ArrayList<>();
        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
//                .paths(Predicates.or(PathSelectors.ant("/manage/**"),PathSelectors.ant("/jkSpjk/**")))
                .paths(PathSelectors.ant("/manage/**"))
                .build()
                .groupName("后台管理接口分组")      //分组名称
                .globalOperationParameters(pars)
                .apiInfo(apiInfo());
    }
    
    @Bean
    public Docket creatExtendApi(){
        List<Parameter> pars = new ArrayList<>();
        return  new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.withClassAnnotation(Controller.class))
                .paths(Predicates.or(PathSelectors.ant("/captcha"),PathSelectors.ant("/download")))
                .build()
                .groupName("扩展接口分组")      //分组名称
                .globalOperationParameters(pars)
                .apiInfo(apiInfo());
    }
    
    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("系统管理/单点登录 Restful API")
                .description("接口服务,【新增】【修改】接口字段默认传null,不要传空字符串")
                .termsOfServiceUrl("")
                .version("1.0")
                .build();
    }
}
